package com.sg.service.biz.bff.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.bff.req.*;
import com.sg.dto.biz.bff.res.*;
import com.sg.service.biz.bff.BusinessObjectService;
import com.sg.common.exception.Assert;
import com.wicket.okrframework.integration.BusinessObjectService;
import com.wicket.okrframework.integration.InductionRecordService;
import com.wicket.okrframework.integration.PowerService;
import com.wicket.okrframework.integration.UserService;
import com.wicket.okrframework.integration.dto.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class BusinessObjectServiceImpl implements BusinessObjectService {

    @Resource
    com.sg.service.biz.framework.InductionRecordService fwBaseInductionRecordClient;
    @Resource
    com.sg.service.biz.framework.BusinessObjectService fwBaseBusinessObjectClient;

    /**
     * B1-1查询对象属性类型关系列表(边界)[2158]
     * gen by moon at 8/10/2022, 3:38:24 AM
     */
    @Trace(operationName = "B1-1查询对象属性类型关系列表(边界)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryObjTypeRelationListBorderRespDto queryObjTypeRelationListBorder(BffQueryObjTypeRelationListBorderReqDto reqDto) {


        QueryObjTypeRelationListRespDto queryObjTypeRelationListRespDto_1 = null;
//步骤0: D1-1查询对象属性类型关系列表 - queryObjTypeRelationList
        QueryObjTypeRelationListRespDto queryObjTypeRelationListRespDto = null;
        QueryObjTypeRelationListReqDto queryObjTypeRelationListReqDto = new QueryObjTypeRelationListReqDto();
        queryObjTypeRelationListReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:63059_1
        if (reqDto != null) {
            queryObjTypeRelationListReqDto.setObjectPropertyId(reqDto.getObjectPropertyId());//sourceId:63058_1
        }

        /*D1-1查询对象属性类型关系列表[384]   */
        Assert.isNull(queryObjTypeRelationListReqDto.getObjectPropertyId(), "B1-1查询对象属性类型关系列表(边界)-D1-1查询对象属性类型关系列表-对象属性ID不能为空", false);
        Assert.isNull(queryObjTypeRelationListReqDto.getSubjectLifeCycle(), "B1-1查询对象属性类型关系列表(边界)-D1-1查询对象属性类型关系列表-主体生命周期不能为空", false);
        queryObjTypeRelationListRespDto = fwBaseBusinessObjectClient.queryObjTypeRelationList(queryObjTypeRelationListReqDto).getData();

        queryObjTypeRelationListRespDto_1 = queryObjTypeRelationListRespDto;

        BffQueryObjTypeRelationListBorderRespDto retData = new BffQueryObjTypeRelationListBorderRespDto();
        if (queryObjTypeRelationListRespDto_1 != null) {
            retData.setObjectPropertyList(queryObjTypeRelationListRespDto_1.getObjectPropertyList().stream().map(item -> BeanUtil.toBean(item, BffObjectPropertyDto.class)).collect(Collectors.toList()));//sourceId:63063_1
        }


        return retData;
    }


    /**
     * B1-3撤销存档就职记录（管理）[969]
     * gen by moon at 9/1/2022, 5:34:15 PM
     */
    @Trace(operationName = "B1-3撤销存档就职记录（管理）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffUndoArchiveInductionRecordRespDto undoArchiveInductionRecord(BffUndoArchiveInductionRecordReqDto reqDto) {


        //步骤0: D1-3撤销想存档就职记录 - undoToArchiveInductionRecord
        UndoToArchiveInductionRecordRespDto undoToArchiveInductionRecordRespDto = null;
        UndoToArchiveInductionRecordReqDto undoToArchiveInductionRecordReqDto = new UndoToArchiveInductionRecordReqDto();
        if (reqDto != null) {
            undoToArchiveInductionRecordReqDto.setInductionRecordId(reqDto.getInductionRecordId());//sourceId:38985_1
            undoToArchiveInductionRecordReqDto.setOriginalRoleMemberId(reqDto.getOriginalRoleMemberId());//sourceId:51686_1
        }

        /*D1-3撤销想存档就职记录[1478]   */
        Assert.isNull(undoToArchiveInductionRecordReqDto.getInductionRecordId(), "B1-3撤销存档就职记录（管理）-D1-3撤销想存档就职记录-就职记录ID不能为空", false);
        Assert.isNull(undoToArchiveInductionRecordReqDto.getOriginalRoleMemberId(), "B1-3撤销存档就职记录（管理）-D1-3撤销想存档就职记录-身份人员ID不能为空", false);
        undoToArchiveInductionRecordRespDto = fwBaseInductionRecordClient.undoToArchiveInductionRecord(undoToArchiveInductionRecordReqDto).getData();


        BffUndoArchiveInductionRecordRespDto retData = new BffUndoArchiveInductionRecordRespDto();


        return retData;
    }

    /**
     * B1-3新增就职记录（管理）[784]
     * gen by moon at 7/23/2022, 9:48:03 PM
     */
    @Trace(operationName = "B1-3新增就职记录（管理）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffAddInductionRecordRespDto addInductionRecord(BffAddInductionRecordReqDto reqDto) {


        AddInductionRecordRespDto addInductionRecordRespDto_1 = null;
//步骤0: D1-3新增就职记录 - addInductionRecord
        AddInductionRecordRespDto addInductionRecordRespDto = null;
        AddInductionRecordReqDto addInductionRecordReqDto = new AddInductionRecordReqDto();
        if (reqDto != null) {
            addInductionRecordReqDto.setPositionId(reqDto.getPositionId());//sourceId:22969_1
            addInductionRecordReqDto.setPositionIdNameId(reqDto.getPositionIdNameId());//sourceId:22970_1
            addInductionRecordReqDto.setPositionIdName(reqDto.getPositionIdName());//sourceId:22971_1
            addInductionRecordReqDto.setOriginalRoleMemberId(reqDto.getOriginalRoleMemberId());//sourceId:22973_1
            addInductionRecordReqDto.setFirstLetter(reqDto.getFirstLetter());//sourceId:22974_1
            addInductionRecordReqDto.setUserId(reqDto.getUserId());//sourceId:22975_1
            addInductionRecordReqDto.setOrganizationId(reqDto.getOrganizationId());//sourceId:22976_1
            addInductionRecordReqDto.setOrganizationName(reqDto.getOrganizationName());//sourceId:22977_1
            addInductionRecordReqDto.setDeptShortName(reqDto.getDeptShortName());//sourceId:35363_1
            addInductionRecordReqDto.setInductionUnitTypeCode(reqDto.getInductionUnitTypeCode());//sourceId:51302_1
            addInductionRecordReqDto.setEntityId(reqDto.getEntityId());//sourceId:22978_1
//            addInductionRecordReqDto.setIsMainInduction(reqDto.getIsMainInduction());//sourceId:22980_1
            addInductionRecordReqDto.setIsCustomPosition(reqDto.getIsCustomPosition());//sourceId:22981_1
            addInductionRecordReqDto.setPositionType(reqDto.getPositionType());//sourceId:35380_1
            addInductionRecordReqDto.setInductionStartTime(reqDto.getInductionStartTime());//sourceId:35381_1
            addInductionRecordReqDto.setDirectorInductionRecordId(reqDto.getDirectorInductionRecordId());//sourceId:22982_1
//            addInductionRecordReqDto.setBatchId(reqDto.getBatchId());//sourceId:22983_1
            addInductionRecordReqDto.setIsPartTimeStaffing(reqDto.getIsPartTimeStaffing());//sourceId:51312_1
            addInductionRecordReqDto.setOrderNumber(reqDto.getOrderNumber());
        }

        /*D1-3新增就职记录[403]   */
        addInductionRecordRespDto = fwBaseBusinessObjectClient.addInductionRecord(addInductionRecordReqDto).getData();

        addInductionRecordRespDto_1 = addInductionRecordRespDto;

        BffAddInductionRecordRespDto retData = new BffAddInductionRecordRespDto();
        if (addInductionRecordRespDto_1 != null) {
            retData.setInductionRecordId(addInductionRecordRespDto_1.getInductionRecordId());//sourceId:29740_1
        }


        return retData;
    }

    /**
     * B1-1删除业务场景
     */
    @Trace(operationName = "B1-1删除业务场景")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffDeleteBizSceneRespDto deleteBizScene(BffDeleteBizSceneReqDto reqDto) {


        //步骤0: D1-1删除业务场景---待删除 - deleteBizScene
        DeleteBizSceneRespDto deleteBizSceneRespDto = null;
        DeleteBizSceneReqDto deleteBizSceneReqDto = new DeleteBizSceneReqDto();
        if (reqDto != null) {
            deleteBizSceneReqDto.setBizSceneId(reqDto.getBizSceneId());//sourceId:25898_1
        }

        /*D1-1删除业务场景---待删除[757]   */
        deleteBizSceneRespDto = fwBaseBusinessObjectClient.deleteBizScene(deleteBizSceneReqDto).getData();


        BffDeleteBizSceneRespDto retData = new BffDeleteBizSceneRespDto();


        return retData;
    }

    /**
     * B1-1删除业务应用
     */
    @Trace(operationName = "B1-1删除业务应用")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffDeleteBizAppSceneRespDto deleteBizAppScene(BffDeleteBizAppSceneReqDto reqDto) {


        //步骤0: D1-1删除业务应用---待删除 - deleteBizAppScene
        DeleteBizAppSceneRespDto deleteBizAppSceneRespDto = null;
        DeleteBizAppSceneReqDto deleteBizAppSceneReqDto = new DeleteBizAppSceneReqDto();
        if (reqDto != null) {
            deleteBizAppSceneReqDto.setBizAppId(reqDto.getBizAppId());//sourceId:25421_1
        }

        /*D1-1删除业务应用---待删除[747]   */
        deleteBizAppSceneRespDto = fwBaseBusinessObjectClient.deleteBizAppScene(deleteBizAppSceneReqDto).getData();


        BffDeleteBizAppSceneRespDto retData = new BffDeleteBizAppSceneRespDto();


        return retData;
    }

}
